﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace Joe.Coin.Monitor.App
{
    public class MonCoinsSection : ConfigurationSection
    {
        //[ConfigurationProperty("height", IsRequired = true)]
        //public int Height
        //{
        //    get
        //    {
        //        return (int)base["height"];
        //    }
        //    set
        //    {
        //        base["height"] = value;
        //    }
        //}

        //[ConfigurationProperty("child", IsDefaultCollection = false)]
        //public CoinSection Child
        //{
        //    get
        //    {
        //        return (CoinSection)base["child"];
        //    }
        //    set
        //    {
        //        base["child"] = value;
        //    }
        //}

        [ConfigurationProperty("allCoins", IsDefaultCollection = false)]
        [ConfigurationCollection(typeof(CoinSection),
            CollectionType = ConfigurationElementCollectionType.AddRemoveClearMap,
            RemoveItemName = "remove")]

        public AllCoins CoinCollection
        {
            get
            {
                return (AllCoins)base["allCoins"];
            }
            set
            {
                base["allCoins"] = value;
            }
        }
    }

    public class CoinSection : ConfigurationElement
    {
        /// <summary>
        /// 币名
        /// </summary>
        [ConfigurationProperty("coinName", IsRequired = true, IsKey = true)]
        public string CoinName
        {
            get
            {
                return (string)base["coinName"];
            }
            set
            {
                base["coinName"] = value;
            }
        }

        /// <summary>
        /// 监控类型（买入、抛出）
        /// </summary>
        [ConfigurationProperty("monType", IsRequired = true)]
        public MonType MonType
        {
            get
            {
                return (MonType)base["monType"];
                 
            }
            set
            {
                base["monType"] = value;
            }
        }

        /// <summary>
        /// 数据源URL
        /// </summary>
        [ConfigurationProperty("url", IsRequired = true)]
        public string Url
        {
            get
            {
                return (string)base["url"];
            }
            set
            {
                base["url"] = value;
            }
        }

        /// <summary>
        /// 价格下限提醒
        /// </summary>
        [ConfigurationProperty("lowTipsPrice", IsRequired = true)]
        public decimal LowTipsPrice
        {
            get
            {
                return (decimal)base["lowTipsPrice"];
            }
            set
            {
                base["lowTipsPrice"] = value;
            }
        }

        /// <summary>
        /// 价格上限提醒
        /// </summary>
        [ConfigurationProperty("highTipsPrice", IsRequired = true)]
        public decimal HighTipsPrice
        {
            get
            {
                return (decimal)base["highTipsPrice"];
            }
            set
            {
                base["highTipsPrice"] = value;
            }
        }
    }

    public class AllCoins : ConfigurationElementCollection
    {
        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((CoinSection)element).CoinName;
        }

        protected override ConfigurationElement CreateNewElement()
        {
            return new CoinSection();
        }

        public CoinSection this[int i]
        {
            get
            {
                return (CoinSection)base.BaseGet(i);
            }
        }

        public CoinSection this[string key]
        {
            get
            {
                return (CoinSection)base.BaseGet(key);
            }
        }
    }
}
